package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ZsyyCommunity;
import com.ruoyi.system.domain.ZsyyPark;
import com.ruoyi.system.mapper.ZsyyCommunityMapper;
import com.ruoyi.system.mapper.ZsyyParkMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class GetCommunityIdImpl {
	@Autowired
	private ZsyyParkMapper parkMapper;
	@Autowired
	private ZsyyCommunityMapper communityMapper;

	public SysUser getLoginUser(){
		SysUser loginUser = new SysUser();
		SysUser user = SecurityUtils.getLoginUser().getUser();	//获取登录用户
		if (!CommonUtil.isEmpty(user.getType()) && user.getType() == 1){
			ZsyyPark park = parkMapper.selectById(user.getAboutId());
			if (!CommonUtil.isEmpty(park)){
				loginUser.setCommunityId(park.getCommunityId());
				loginUser.setParkId(park.getId());
				loginUser.setParkCode(park.getParkCode());
			}
		}else if (!CommonUtil.isEmpty(user.getType()) && user.getType() == 2){
			ZsyyCommunity community = communityMapper.selectById(user.getAboutId());
			if (!CommonUtil.isEmpty(community)){
				loginUser.setCommunityId(community.getId());
			}

		}else {
			loginUser.setCommunityId(null);
		}
		return loginUser;
	}
}
